package cn.zm.trip.web.controller;

import cn.zm.trip.web.domain.*;
import cn.zm.trip.web.dto.TravelInfoQueryDTO;
import cn.zm.trip.web.service.TravelInfoService;
import cn.zm.trip.web.vo.HotelVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 旅游资讯相关
 */
@Controller
@RequestMapping("/travel/info")
public class TravelInfoController {

    @Autowired
    private TravelInfoService travelInfoService;

    @GetMapping("/index")
    public String listTravelInfo(Model model, TravelInfoQueryDTO queryDTO) {
        LambdaQueryWrapper<TravelInfo> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(queryDTO.getTitle())) {
            queryWrapper.like(TravelInfo::getTitle, queryDTO.getTitle());
        }
        List<TravelInfo> list = travelInfoService.list(queryWrapper);
        model.addAttribute("forums", list);
        return "proscenium/trip/index";
    }

    /**
     * 跳转首页
     */
    @GetMapping("/content")
    public String content(Integer id, Model model) {


        TravelInfo one = travelInfoService.getOne(new LambdaQueryWrapper<TravelInfo>().eq(TravelInfo::getId, id));
        model.addAttribute("forum", one);

        return "proscenium/trip/content";
    }
}
